package com.wlyuan.open.domain.source.assembler;

import com.wlyuan.core.domain.MappingIds;
import com.wlyuan.core.marker.NamedStatus;
import com.wlyuan.open.dto.OpenCombineSyncDTO;
import com.wlyuan.open.dto.order.OrderTransportDTO;
import com.wlyuan.transport.dto.common.OrderMultiTransportDTO;
import com.wlyuan.transport.rewrite.dto.CombineRewriteDTO;
import org.mapstruct.Mapper;
import org.mapstruct.Mapping;
import org.mapstruct.Mappings;
import org.mapstruct.factory.Mappers;

/**
 * @author lijing
 * @description
 */
public class CombineAssembler {

    private static final Assembler ASSEMBLER = Mappers.getMapper(Assembler.class);

    @Mapper(uses = {
            MappingIds.class,
    }, imports = {
            NamedStatus.class,
    })
    public interface Assembler {
        @Mappings({
                @Mapping(source = "transportIds", target = "waybills"),
                @Mapping(source = "orderNo", target = "combineNo"),

                @Mapping(source = "customerId", target = "customer.customerId"),

                @Mapping(source = "carrierId", target = "carrier.carrierId"),
                @Mapping(source = "carrierContactName", target = "carrier.carrierContactName"),
                @Mapping(source = "carrierPhone", target = "carrier.carrierContactMobile"),

                @Mapping(source = "deviceCode", target = "device.deviceCode"),
                @Mapping(source = "trackType", target = "device.trackType"),
                @Mapping(source = "transports", target = "device.transports"),
                @Mapping(source = "cost", target = "fee"),
                @Mapping(source = "cost.minimumFee", target = "fee.minCost"),
                @Mapping(source = "cost.recalculated", target = "fee.refresh"),
                @Mapping(source = "cost.status", target = "fee.quotationStatus"),
        })
        CombineRewriteDTO assemble(OpenCombineSyncDTO source);


        @Mappings({
                @Mapping(source = "type", target = "transportType"),
                @Mapping(source = "no", target = "transitNo"),
                @Mapping(source = "remark", target = "remarks"),
                @Mapping(source = "arrive", target = "arriveFlag"),
                @Mapping(source = "wayTo", target = "wayAddress"),
        })
        OrderMultiTransportDTO assemble(OrderTransportDTO source);

    }

    public static CombineRewriteDTO assemble(OpenCombineSyncDTO source) {
        return ASSEMBLER.assemble(source);
    }
}
